--Borrar anteriores modificaciones
alter table dbo.corn_futures_versions
	drop constraint fk_corn_future_origin_version, 
		constraint df_imported_version,
		column corn_origin
go
alter table dbo.corn_futures
	drop constraint fk_corn_future_origin, 
		constraint df_imported,
		column corn_origin
go
alter table dbo.corns_types
	drop constraint fk_corn_type_origin, 
		constraint df_imported_type,
		column corn_origin
go
drop table dbo.corns_origins
go
create table dbo.corns_origins(
	corn_origin char(1) primary key not null,
	description varchar(255) not null
)
go
insert into dbo.corns_origins values ('I', 'Importado')
go
insert into dbo.corns_origins values ('N', 'Nacional')
go

--Agrega campo de origen de maiz a la tabla de futuros
alter table dbo.corn_futures
	add corn_origin char(1) not null constraint df_imported default 'I'
go
alter table dbo.corn_futures
	add constraint fk_corn_future_origin foreign key (corn_origin)  references dbo.corns_origins(corn_origin)
go

--Agrega campo de origen de maiz a la tabla de futuros en la version
alter table dbo.corn_futures_versions
	add corn_origin char(1) not null constraint df_imported_version default 'I'
go
alter table dbo.corn_futures_versions
	add constraint fk_corn_future_origin_version foreign key (corn_origin)  references dbo.corns_origins(corn_origin)
go

delete from dbo.tables where table_id = 2
go
insert into dbo.tables (table_id, table_name, description) values (2, 'bushels', 'Mantenimiento de precios bushel')
go

--Agregar el origen de maiz a la tabla de tipo de maiz
alter table dbo.corns_types
	add corn_origin char(1) not null constraint df_imported_type default 'I'
go
alter table dbo.corns_types
	add constraint fk_corn_type_origin foreign key (corn_origin) references dbo.corns_origins(corn_origin)
go
update corns_types
set corn_origin = 'N'
where corn_type_id = 1
go

--Agregar la cantidad promedio a los tipos de cambio
alter table exchanges_rates_versions
	add avg_amount decimal(18, 4) not null default 0
go

